//
//  LoginSettingConfig.m
//  Romens.XSBalance
//
//  Created by 李美东 on 16/3/14.
//  Copyright © 2016年 孙博. All rights reserved.
//

#import "LoginSettingConfig.h"
#import "ToolHelper.h"

@implementation LoginSettingConfig
-(void)SetUI:(UITextField*)usernameTextField  pwd:(UITextField*)passwordTextField  btnlogin:(UIButton*)loginButton btnregister:(UIButton*)registerButton viewController:(UIViewController*) viewcontroller
{
    //背景颜色    [UIColor colorWithRed:250/255.0 green:250/255.0 blue:250/255.0 alpha:1.0f]
    viewcontroller.view.backgroundColor =RGBA(250,250,250, 1);
    viewcontroller.title = @"登录";
    //自定义输入框背景view
    UIView *backView = [[UIView alloc]init];
    backView.translatesAutoresizingMaskIntoConstraints = NO;
    [viewcontroller.view addSubview:backView];
    backView.backgroundColor = [UIColor whiteColor];
    backView.layer.cornerRadius = 3.0f;
    backView.layer.masksToBounds = YES;
    //给图层添加一个有色边框
    backView.layer.borderWidth = 1;
    backView.layer.borderColor = [RGB(225,225,225) CGColor];
    
    //线
    UIView *lineView = [[UIView alloc]init];
    lineView.translatesAutoresizingMaskIntoConstraints = NO;
    lineView.backgroundColor=RGB(225,225,225);
    [backView addSubview:lineView];
    
    UIImageView *nameIcon = [[UIImageView alloc]init];
    nameIcon.image = [UIImage imageNamed:@"user"];
    nameIcon.translatesAutoresizingMaskIntoConstraints = NO;
    [backView addSubview:nameIcon];
    
    UIImageView *passIcon = [[UIImageView alloc]init];
    passIcon.image = [UIImage imageNamed:@"pwd"];
    passIcon.translatesAutoresizingMaskIntoConstraints = NO;
    [backView addSubview:passIcon];
    
    UIImageView *registerIcon = [[UIImageView alloc]init];
    registerIcon.hidden=YES;
    registerIcon.image = [UIImage imageNamed:@"help"];
    registerIcon.translatesAutoresizingMaskIntoConstraints = NO;
    [viewcontroller.view addSubview:registerIcon];
    
    
    //控件 输入框
    usernameTextField.translatesAutoresizingMaskIntoConstraints=NO;
    usernameTextField.clearButtonMode = UITextFieldViewModeAlways;
    usernameTextField.placeholder = @"请输入您的账户或手机号";
    [backView addSubview:usernameTextField];
    
    passwordTextField.translatesAutoresizingMaskIntoConstraints = NO;
    passwordTextField.secureTextEntry = YES; //安全输入
    passwordTextField.placeholder = @"请输入密码";
    passwordTextField.clearButtonMode = UITextFieldViewModeAlways;
    [backView addSubview:passwordTextField];
    
    
    //登录按钮
    loginButton.translatesAutoresizingMaskIntoConstraints = NO;
    [loginButton setTitle:@"登录" forState:UIControlStateNormal];
    [loginButton setBackgroundColor:SystemColor];
    [loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    loginButton.layer.cornerRadius = 5.0f;//圆角半径
    [viewcontroller.view addSubview:loginButton];
    
    //忘记密码按钮
    registerButton.translatesAutoresizingMaskIntoConstraints = NO;
    registerButton.titleLabel.textAlignment=NSTextAlignmentRight;
    [registerButton setTitle:@"忘记密码" forState:UIControlStateNormal];
    [registerButton setTitleColor:SystemColor forState:UIControlStateNormal];
    [viewcontroller.view addSubview:registerButton];
    
    UILabel*labwarm=[[UILabel alloc]init];
    labwarm.translatesAutoresizingMaskIntoConstraints=NO;
    labwarm.font=systemDetailFont;
    labwarm.text=@"温馨提示:获取短信密码即为登陆密码";
    [viewcontroller.view addSubview:labwarm];
    
    [viewcontroller.view addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(backView) format:@"H:|-15-[backView]-15-|"]];
    
    [viewcontroller.view addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(labwarm) format:@"H:|-15-[labwarm]-15-|"]];
    
    [viewcontroller.view addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(backView,loginButton,lineView,registerButton,labwarm) format:@"V:|-20-[backView(==89)]-[labwarm(25)]-[loginButton(==44)]-15-[registerButton(==30)]"]];
    
    //线
    [backView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(lineView) format:@"H:|[lineView]|"]];
    [backView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(lineView) format:@"V:|-44-[lineView(==1)]"]];
    
    [backView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(nameIcon,usernameTextField) format:@"H:|-10-[nameIcon(==15)]-8-[usernameTextField]|"]];
    [backView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(nameIcon) format:@"V:|-14.5-[nameIcon(==15)]"]];
    
    [backView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(passIcon,passwordTextField) format:@"H:|-10-[passIcon(==15)]-8-[passwordTextField]|"]];
    [backView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(passIcon) format:@"V:[passIcon(==15)]-14.5-|"]];
    
    [backView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(usernameTextField) format:@"V:|[usernameTextField(==44)]"]];
    
    [backView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(passwordTextField) format:@"V:[passwordTextField(==44)]|"]];
    
    //按钮 水平
    [viewcontroller.view addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(loginButton) format:@"H:|-15-[loginButton]-15-|"]];
    
    [viewcontroller.view addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(registerIcon,registerButton) format:@"H:[registerIcon(==15)]-3-[registerButton(==160)]-5-|"]];
    
    [viewcontroller.view addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(registerIcon) format:@"V:[registerIcon(==15)]"]];
    
    [viewcontroller.view  addConstraint:[NSLayoutConstraint constraintWithItem:registerIcon
                                                                     attribute:NSLayoutAttributeCenterY
                                                                     relatedBy:NSLayoutRelationEqual
                                                                        toItem:registerButton                                                        attribute:NSLayoutAttributeCenterY
                                                                    multiplier:1.0f
                                                                      constant:0]];
    
}

@end
